package com.soft.link.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.soft.link.mapper.TsUserMapper;
import com.soft.link.model.TsUser;
import com.soft.link.service.TsUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * company 重庆庆云石油工程技术有限责任公司
 * FileName TsUserServiceImpl
 * Package com.soft.link.impl
 * Description 人员基本信息服务实现
 * author Administrator
 * create 2018-03-31 22:05
 * version V1.0
 */
@Service
public class TsUserServiceImpl implements TsUserService {

    @Autowired(required = false)
    TsUserMapper tsUserMapper;

    /**
     * @param loginName 登录名
     * @param password  密码
     * @throws {如果有异常说明请填写}
     * @methodname findTsUser
     * @Description {填写方法注释说明}
     * @author 黄学乾
     * @create 2018/3/31/031 22:07
     */
    @Override
    public TsUser findTsUser(String loginName, String password) throws Exception {
        Map param = new HashMap<>();
        param.put("loginName", loginName);
        param.put("password", password);
        TsUser tsUser = tsUserMapper.findTsUser(param);
        return tsUser;
    }
    /**
    * @methodname findTsUserList 
    * @Description 根据查询，
    * @author 黄学乾
    * @create 2018/4/5/005 21:52
    * @param  * @param tsUser
    */
    @Override
    public List<TsUser> findTsUserList(TsUser tsUser) throws Exception {
        return tsUserMapper.findTsUserList(tsUser);
    }

    /**
    * @methodname  findTsUserPage
    * @Description 账户列表分页查询
    * @author 黄学乾
    * @create 2018/4/23/023 15:59
    * @param  * @param tsUser
    * @throws {数据库连接超时和查询失败}
    * @return 
    */
    @Override
    public JSONObject findTsUserPage(TsUser tsUser) throws Exception {
        JSONObject returnObj = new JSONObject();
        PageHelper.startPage(tsUser.getOffset(), tsUser.getLimit());
        List<TsUser> tsUserList = findTsUserList(tsUser);
        // 取分页信息
        PageInfo<TsUser> pageInfo = new PageInfo<TsUser>(tsUserList);
        returnObj.put("total",pageInfo.getTotal());
        returnObj.put("rows", JSON.toJSON(tsUserList));
        return returnObj ;
    }
}
